﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using BDD.TicTacToe.Domain;
using BDD.TicTacToe.Ui.Mvc.Models;
using MvcContrib.TestHelper;
using NUnit.Framework;
using Rhino.Mocks;

namespace BDD.TicTacToe.Core.Tests.Controller_Specs
{
    public class When_displaying_a_game_page : with_given_GamePlayController
    {
        private ActionResult _result;
        private string _playerX;
        private Guid _gameId;
        private Game _game;

        [SetUp]
        public void When()
        {
            _playerX = "Scott";

            _gameId = Guid.NewGuid();

            _game = new Game(_playerX, "Simon");

            GameRepository.Stub(x => x.FindBy(_gameId)).Return(_game);

            _result = Sut.Display(_gameId);
        }

        [Test]
        public void Then_the_controller_should_ask_the_repository_for_the_game()
        {
            GameRepository.AssertWasCalled(x => x.FindBy(_gameId)); 
        }

        [Test]
        public void Then_the_view_model_should_know_the_next_player_to_place_his_token()
        {
            _result.AssertResultIs<ViewResult>();

            var viewResult = (ViewResult) _result;

            Assert.That(viewResult.ViewData.Model, Is.TypeOf(typeof(GameDisplayViewModel)));

            var viewModel = (GameDisplayViewModel) viewResult.ViewData.Model;            

            Assert.That(viewModel.NextPlayerToPlaceToken, Is.EqualTo(_playerX));
        }
    }
}
